﻿// 物体基类

using Share;
using System;
using UnityEngine;
public abstract class ObjectBase : MonoBehaviour
{
    public virtual string GetTableName()
    {
        return gameObject.name;
    }
    public virtual long GetTableID()
    {
        return -1;
    }

    private long m_sceneID = -1;//场景对象id

    public long SceneID
    {
        get { return m_sceneID; }
    }

    static int m_ScenePointer = -1000;
    public static int GetScenePointer()
    {
        m_ScenePointer = m_ScenePointer--;
        return m_ScenePointer;
    }    // 初始化角色

    long m_ID;
    string m_strGuid;

    public long ID
    {
        get { return m_ID; }
    }

    public string GUID
    {
        get { return m_strGuid; }
    }

    public bool DoInit(string guid)
    {
        m_strGuid = guid;
        m_sceneID = GetScenePointer();//已赋值，则使用赋值的sceneID作为自己的ID，未赋值则本地会默认生成
        OnInitGUID();
        OnInitState();
        OnInitLogic();
        return true;
    }
    // 初始化角色
    public bool DoInit(long nID = -1, long sceneID = -1)
    {
        try
        {
            m_ID = nID;
            if (sceneID < 0)
                m_sceneID = GetScenePointer();//已赋值，则使用赋值的sceneID作为自己的ID，未赋值则本地会默认生成
            else
                m_sceneID = sceneID;
            OnInitID();
            OnInitState();
            OnInitLogic();
        }
        catch (Exception exception)
        {
            XKLog.LogError(exception.Message);
            return false;
        }
        return true;
    }

    void Update()
    {
        OnUpdate();
        if (m_bDestroy)
        {
            OnDestory();
        }
    }

    public virtual void OnDestory()
    {
    }

    protected bool m_bDestroy = false;
    protected virtual bool OnUpdate()
    {
        return true;
    }
    protected virtual void OnInitGUID()
    {

    }
    protected virtual void OnInitID()
    {

    }
    protected virtual void OnInitState()
    {

    }
    protected virtual void OnInitLogic()
    {

    }

    public virtual void DoSendStateEnterMessage(string strState)
    {

    }
}
